//
//  ViewController.m
//  29-HomeWork_TransitionAnimation
//
//  Created by dllo on 16/8/23.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ViewController.h"
#import "MyTableViewCell.h"
#import "SecondViewController.h"
#import "PushTransitionAnimation.h"
#import "PopTransitionAnimation.h"
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate>
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;
    // Do any additional setup after loading the view, typically from a nib.
    self.imageArray = [NSMutableArray array];
    self.navigationController.delegate = self;
    [self handleData];
    
}
- (void)handleData {
    for (int i = 0; i < 11; i++) {
        NSString *imageName = [NSString stringWithFormat:@"%d.jpg", i];
        [self.imageArray addObject:imageName];
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _imageArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    self.cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    _cell.imageOfCell.image = [UIImage imageNamed:_imageArray[indexPath.row]];
//    self.currentIndexPath = indexPath;
    return _cell;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    MyTableViewCell *cell = sender;
    NSIndexPath *indexPath = [_tableView indexPathForCell:cell];
    self.currentIndexPath = indexPath;
    SecondViewController *second = [SecondViewController new];
    second = segue.destinationViewController;
    second.imageName = _imageArray[indexPath.row];

}

- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC {
    
    if (operation == UINavigationControllerOperationPush) {
        PushTransitionAnimation *push = [[PushTransitionAnimation alloc] init];
        return push;
    } else if (operation == UINavigationControllerOperationPop) {
        PopTransitionAnimation *pop = [[PopTransitionAnimation alloc] init];
        return pop;
    } else {
        
    }
    return nil;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
